package com.ny.demo524;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Update {public static void main(String[] args) throws SQLException {
    Scanner scanner = new Scanner(System.in);

    System.out.println("请输入用户id");
    int id = scanner.nextInt();
    System.out.println("请输入修改后的用户名");
    String username = scanner.next();
    Connection connection = SqlConnection.getCon();
    String sql = "update  users set username =? where id = ?;";
    PreparedStatement preparedStatement = connection.prepareStatement(sql);
    preparedStatement.setString (1, username);
    preparedStatement.setInt (2, id);
    int i =  preparedStatement.executeUpdate();
    if(i>0){
        System.out.println("修改用户名成功");
    }else{
        System.out.println("修改用户名失败");
    }

}

}
